/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ai;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author root
 */
public class CondExp extends LexExp{    
    public CondExp(){
        
    }
    public CondExp(LexExp pLeft, LexExp pRight) throws ParseException{
        setLeft(pLeft);
        setRight(pRight);  
    }
    public void setLeft(LexExp pExp) throws ParseException{
        if(pExp instanceof BoolExp){
            mLeft = (BoolExp)pExp;
        }
        else{
            throw new ParseException("CondExp.setLeft(Expression pExp): pExp is not a BoolExp!!!");
        }
    }
    public void setRight(LexExp pExp) throws ParseException{
        if(!(pExp instanceof BoolExp) ){
            mRight = pExp;
        }
        else{
            throw new ParseException("CondExp.setRight(Expression pExp): pExp is a BoolExp!!!");
        }
    }
    public LexExp substitute(String pLabelName, String pString){
        try {
            return new CondExp(mLeft.substitute(pLabelName, pString), mRight.substitute(pLabelName, pString));
        } catch (ParseException ex) {
            Logger.getLogger(CondExp.class.getName()).log(Level.SEVERE, null, ex);
            return this;
        }
    }
    public LexExp evalCond(){
        if (mLeft.evaluate()){
            return mRight;
        }
        else {
            return null;
        }
    }

    private BoolExp mLeft;
    private LexExp mRight;
}
